package ext.generic.wfaugment.processors;

import wt.doc.WTDocument;
import wt.doc.WTDocumentMaster;

import wt.part.*;

import java.util.*;
import java.util.Vector.*;

import wt.util.*;

import wt.vc.*;

import wt.fc.*;
import wt.fc.collections.WTHashSet;

import java.io.*;

import org.apache.poi.xssf.usermodel.*;
import org.springframework.web.HttpRequestHandler;

import com.ptc.core.components.descriptor.ComponentModel;
import com.ptc.core.components.rendering.guicomponents.CheckBox;
import com.ptc.core.components.rendering.guicomponents.GUIComponentArray;
import com.ptc.core.components.tags.propertyPanel.RenderPropertyLabelTag;
import com.ptc.netmarkets.model.NmOid;

import wt.session.*;

import wt.type.ClientTypedUtility;

import java.text.DateFormat;

import javax.servlet.http.HttpServletRequest;

import wt.vc.baseline.ManagedBaseline;
import wt.vc.views.ViewHelper;
import wt.workflow.engine.ProcessData;
import wt.workflow.engine.WfActivity;
import wt.workflow.engine.WfVariable;
import wt.workflow.work.WorkItem;

import ext.com.iba.IBAUtil;
import ext.com.core.CoreUtil;

import wt.inf.container.*;

import wt.org.*;

import wt.pdmlink.*;

import wt.inf.library.*;

import wt.epm.*;

import wt.change2.*;

import wt.csm.navigation.*;


import wt.projmgmt.admin.Project2;

public class WfAugmentUtil
{
 
    private static WTContext wtcontext = WTContext.getContext();
    public static WTProperties wtproperties;
    private static Locale locale = null;
    private static boolean VERBOSE = false;
    private static String CLASSNAME = WfAugmentUtil.class.getName();
    private static String WFGUIDE = "wfGuide";
    public static Hashtable container2label = new Hashtable(); // 容器类与签审指南标记对应表
    public static Hashtable class2label = new Hashtable(); // 业务对象类与签审指南标记对应表
    private static final String RESOURCE = "ext.generic.wfaugment.processors.processorsResource";

    static
    {
        wtproperties = null;
        try
        {
            container2label.put(WTLibrary.class.getName(), "WTLibrary");
            container2label.put(PDMLinkProduct.class.getName(), "PDMLinkProduct");
            container2label.put(Project2.class.getName(), "Project2");
            class2label.put(WTDocument.class.getName(), "doc");
            class2label.put(WTPart.class.getName(), "part");
            class2label.put(EPMDocument.class.getName(), "cad");
            class2label.put(WTChangeOrder2.class.getName(), "ecn");
            class2label.put(WTChangeActivity2.class.getName(), "eca");
            class2label.put(WTChangeRequest2.class.getName(), "ecr");
            class2label.put(WTChangeIssue.class.getName(), "pr");
            class2label.put(ManagedBaseline.class.getName(), "bsline");

            wtproperties = WTProperties.getLocalProperties();
            VERBOSE = wtproperties.getProperty("ext.generic.wfaugment.verbose", false);
            locale = wtcontext.getLocale();
        }
        catch (Throwable throwable)
        {
            throw new ExceptionInInitializerError(throwable);
        }
    }

    /**
     * 读取指定Sheet中指定活动名称的签审信息，同时构造出签审环节
     * 
     * @param pbo           主业务对象
     * @param activityName  活动名字
     * @param sheetName     execl中sheet的名字
     * @param huanjie       环节名字
     * @return              指定Sheet中指定活动名称的签审信息
     * @throws IOException
     * @throws WTException
     */
    public static String getReviewGuide(Persistable pbo, String activityName, String sheetName, StringBuffer huanjie) throws IOException, WTException
    {
        if (VERBOSE)
            System.out.println(">>>" + CLASSNAME + ".getReviewGuide() --- activityName=" + activityName + "--- sheetName=" + sheetName);

        String wfConfigFilePath = getConfigFilePath(pbo);
        if (VERBOSE)
            System.out.println("\t 签审指南路径=" + wfConfigFilePath);
        if (wfConfigFilePath == null || wfConfigFilePath.length() == 0)
            return null;

        XSSFWorkbook wb = new XSSFWorkbook(new FileInputStream(wfConfigFilePath));
        if (wb == null)
        {
            if (VERBOSE)
                System.out.println("\t 签审指南路径 workbool is null");
            return null;
        }

        String detailType = "";
        String bigType = "";
        XSSFSheet sheet = wb.getSheet(sheetName);
        if (sheet == null)
        {
            if (VERBOSE)
                System.out.println("\t 签审指南路径 sheet is null");
            return null;
        }
        Iterator rows = sheet.rowIterator();
        int rowNumber = 0;
        int nActivityCol = 0;
        String cellValue = "";
        XSSFRow row;
        XSSFCell cell;

        if (VERBOSE)
            System.out.println("\t 签审指南路径 instanceof start");

        if (pbo instanceof WTDocument)
        {
            WTDocument doc = (WTDocument) pbo;
            bigType = getDocType(doc);
            Hashtable ibaValues = IBAUtil.getIBAValues(doc);
            String docType = getPropertiesValue("ext.generic.wfaugment.wfaugment", "wf.doc.smallType");
            detailType = (String) ibaValues.get(docType);
            if (VERBOSE)
                System.out.println("\t 文档大类为 " + bigType + "，文档小类软属性为 " + docType + "，其值为 " + detailType);
            if (detailType == null)
                detailType = "";
            if (VERBOSE)
                System.out.println("	最终小类为:" + detailType);
            int nSheetRow = sheet.getLastRowNum();
            if (VERBOSE)
                System.out.println("nSheetRow = " + nSheetRow);
            row = sheet.getRow(0);

            int nSheetCol = row.getLastCellNum();
            if (VERBOSE)
                System.out.println("nSheetCol = " + nSheetCol);
            //小类的位置
            for (int i = 1; i <= nSheetRow; i++)
            {
                //文档大类
                String s = getExcelCellContent(sheet, i, 0);
                if (VERBOSE)
                    System.out.println("EXCEL文档大类 = " + s);
                if (bigType.length() != 0 && (s.equalsIgnoreCase(bigType)))
                {
                    //针对无小类的文档大类：取文档大类所在行的下一行
                    if (detailType.length() == 0)
                    {
                        rowNumber = i;
                        break;
                    }
                    else
                    {
                        //文档小类,从下一行开始找
                        for (int j = i + 1; j < nSheetRow; j++)
                        {
                            String ss = getExcelCellContent(sheet, j, 1);
                            if (VERBOSE)
                                System.out.println("EXCEL文档小类 = " + s);
                            //到达下一个大类时跳出循环
                            if (ss == null || ss.length() == 0)
                                break;
                            else if (detailType.length() != 0 && ss.equalsIgnoreCase(detailType))
                            {
                                rowNumber = j;
                                break;
                            }
                        }
                    }
                }
                if (rowNumber != 0)
                    break;
            }
            if (rowNumber == 0)
            {
                throw new WTException("签审指南中没有对应的文档大类或小类");
            }
        }
        else if (pbo instanceof WTPart)
        {
            WTPart part = (WTPart) pbo;
            boolean noSmallType = false;
            String smallType = WfAugmentUtil.getPropertiesValue("ext.generic.wfaugment.wfaugment", "wf.part.smallType");
            if (VERBOSE)
                System.out.println("	&&&&DEBUG:	零部件类型软属性名称 = " + smallType);
            if (smallType == null || smallType.length() == 0)
            {
                if (VERBOSE)
                    System.out.println("	&&&&DEBUG:	系统未定义零部件类型软属性，直接读取签审指南的第二行。。。");
                noSmallType = true;
            }
            if (noSmallType)
                rowNumber = 1;
            else
            {
                Hashtable ibaValues = IBAUtil.getIBAValues(part);
                String partAttribute = (String) ibaValues.get(smallType);
                partAttribute = partAttribute != null? partAttribute: "";
                row = (XSSFRow) rows.next();
                do
                {
                    if (!rows.hasNext())
                        break;
                    cell = row.getCell((short) 0);
                    if (cell != null)
                    {
                        cellValue = cell.getStringCellValue().trim();
                        if (cellValue.equals(partAttribute))
                        {
                            rowNumber = row.getRowNum();
                            break;
                        }
                    }
                    row = (XSSFRow) rows.next();
                }
                while (true);
            }
        }
        else if (pbo instanceof WTChangeOrder2)
        {
            WTChangeOrder2 ecn = (WTChangeOrder2) pbo;
            bigType = getECNType(ecn);
            
            if (VERBOSE)
            {
                System.out.println("	&&&&DEBUG:	变更通告变更类型为 = " + bigType);
            }
            // 由于MOON不使用ECN小类，只使用ECN大类，所以只判断ECN大类 【KEVIN XU】
            if (bigType == null || bigType.length() == 0)
            {
                if (VERBOSE)
                    System.out.println("	&&&&DEBUG:	变更扩展类型为空，直接读取签审指南的第二行！");
            }
            row = (XSSFRow) rows.next();
            do
            {
                if (!rows.hasNext())
                    break;
                cell = row.getCell((short) 0);
                if (cell != null)
                {
                    cellValue = cell.getStringCellValue().trim();
                    if (cellValue.equals(bigType))
                    {   
                        rowNumber = row.getRowNum();
                        System.out.println("00000000000000000000000");
                        break;
                    }
                }
                row = (XSSFRow) rows.next();
            }
            while (true);
        }
        else if (pbo instanceof EPMDocument)
        {
            // KEVIN XU MODIFY
            // 增加EPMDocument读取方式
            System.out.println("EPMDocument对象，直接读取第二行");
            rowNumber = 1;
        }
        else if (pbo instanceof WTChangeRequest2)
        {
            // KEVIN XU MODIFY
            // 增加WTChangeRequest2读取方式
            if (VERBOSE)
                System.out.println("WTChangeRequest2对象，直接读取第二行");
            rowNumber = 1;
        }
        else
        {
            rowNumber = 1;
        }
        if (VERBOSE)
            System.out.println("\t 签审指南路径 instanceof end");
        if (VERBOSE)
            System.out.println("\t rowNumber = " + rowNumber);

        // 获取第一行，判断签审环节
        row = sheet.getRow(0);
        for (int i = 0; i < row.getLastCellNum(); i++)
        {
            cell = row.getCell((short) i);
            if (cell == null)
                continue;
            cellValue = cell.getStringCellValue().trim();
            if (!cellValue.equals(activityName))
                continue;
            nActivityCol = i;
            break;
        }

        if (VERBOSE)
            System.out.println("\t nActivityCol = " + nActivityCol);
        XSSFRow row1 = sheet.getRow(rowNumber);
        cell = row1.getCell((short) nActivityCol);
        if (VERBOSE)
            System.out.println("\t cell = " + cell);
        if (cell != null)
        {
            String roleValue = cell.getStringCellValue();
            if (VERBOSE)
                System.out.println("\t roleValue=" + roleValue);
            roleValue = roleValue.trim();
            if (roleValue.startsWith("Y"))
            {
                if (VERBOSE)
                    System.out.println("\t 活动 " + activityName + " 为必选环节");
                huanjie = huanjie.append(activityName + "->");
            }
            else if (roleValue.startsWith("S"))
            {
                if (VERBOSE)
                    System.out.println("\t 活动 " + activityName + " 为可选环节");
                huanjie = huanjie.append("(" + activityName + ")" + "->");
            }
            else if (VERBOSE)
                System.out.println("\t 活动 " + activityName + " 不需要签审");
            return roleValue;
        }
        else
        {
            return null;
        }
    }

    /**
     * 根据PBO的对象类别以及所属产品库或存储库，得到其对应的流程签审指南文件
 
     * @param pbo   主业务对象
     * @return      流程签审指南文件地址
     * @throws IOException
     * @throws WTException
     */
    public static String getConfigFilePath(Persistable pbo) throws IOException, WTException
    {
        String configFilePath = "";
        String propertyName = "";
        if (pbo instanceof WTContained)
        {
            WTContained containedObj = (WTContained) pbo;
            WTContainer container = containedObj.getContainer();
            String orgName = container.getOrganizationName();
            String containerName = container.getName();
            configFilePath = getConfigFilePath(container, pbo.getClass());
        }
        else
        {
            Locale locale = SessionHelper.manager.getLocale();
            throw new WTException(propertyName + WTMessage.getLocalizedMessage(RESOURCE, "11", null, locale));
        }
        return configFilePath;
    }

    /**
     * 根据容器以及对象类型，得到其对应的流程签审指南文件
     * 
     * @param container  容器对象
     * @param objClass   对象类型
     * @return           流程签审指南文件的地址
     * @throws IOException
     * @throws WTException
     */
    public static String getConfigFilePath(WTContainer container, Class objClass) throws IOException, WTException
    {
        if (VERBOSE)
            System.out.println(">>>" + CLASSNAME + ".getConfigFilePath()");
        String configFilePath = "";
        String propertyName = "";
        String orgName = container.getOrganizationName();
        String containerName = container.getName();

        // 获取容器以及对象类的签审指南标识  
        String containerLabel = (String) container2label.get(container.getClass().getName());
        String classLabel = (String) class2label.get(objClass.getName());
        if (containerLabel == null || classLabel == null)
        {
            Locale locale = SessionHelper.manager.getLocale();
            throw new WTException(propertyName + WTMessage.getLocalizedMessage(RESOURCE, "11", null, locale));
        }

        propertyName = "ext." + orgName + "." + containerLabel + "." + containerName + "." + classLabel + "." + WFGUIDE;

        // 如果site.conf里没有定义，则使用缺省的ext.组织名称.default.doc.wfGuide
        configFilePath = wtproperties.getProperty(propertyName, "");
        if (configFilePath == null || configFilePath.length() == 0)
        {
            propertyName = "ext." + orgName + "." + "default." + classLabel + "." + WFGUIDE;
            configFilePath = wtproperties.getProperty(propertyName, "");
        }

        configFilePath = configFilePath.replace('/', File.separatorChar);
        configFilePath = configFilePath.replace('\\', File.separatorChar);
        if (configFilePath.length() == 0)
        {
            Locale locale = SessionHelper.manager.getLocale();
            throw new WTException(propertyName + WTMessage.getLocalizedMessage(RESOURCE, "11", null, locale));
        }
        if (VERBOSE)
        {
            System.out.println("	ConfigFilePath=" + configFilePath);
            System.out.println("<<<" + CLASSNAME + ".getConfigFilePath()");
        }
        return configFilePath;
    }

    /**
     * Get Part Apply Config File Path
     */
    public static String getPartApplyConfigFilePath() throws IOException, WTException
    {
        if (VERBOSE)
            System.out.println(">>>" + CLASSNAME + ".getConfigFilePath()");
        String wfConfigFilePath = "";
        String propertyName = "";


        propertyName = "ext.MOON.default.partApply.wfGuide";

        // 如果site.conf里没有定义，则使用缺省的ext.组织名称.default.doc.wfGuide
        WTProperties wtproperties = WTProperties.getLocalProperties();
        wfConfigFilePath = wtproperties.getProperty(propertyName, "");

        wfConfigFilePath = wfConfigFilePath.replace('/', File.separatorChar);
        wfConfigFilePath = wfConfigFilePath.replace('\\', File.separatorChar);
        if (wfConfigFilePath.length() == 0)
        {
            Locale locale = SessionHelper.manager.getLocale();
            throw new WTException(propertyName + WTMessage.getLocalizedMessage(RESOURCE, "11", null, locale));
        }
        if (VERBOSE)
        {
            System.out.println("	ConfigFilePath=" + wfConfigFilePath);
        }

        return wfConfigFilePath;
    }
    /**
     * 由文档对象获取文档类型
     * @param doc    文档对象
     * @return       文档类型
     * @throws IOException
     * @throws WTException
     */

    public static String getDocType(WTDocument doc) throws IOException, WTException
    {
        String docType = "";
        Locale locale = SessionHelper.manager.getLocale();

        docType = ClientTypedUtility.getLocalizedTypeName(doc, locale.CHINA);
        if (VERBOSE)
        {
            System.out.println("	local=" + locale.getDisplayName());
            System.out.println("	local=" + locale.CHINA.getDisplayName());
            System.out.println("	local=" + locale.CHINA.getDisplayCountry());
            System.out.println("	local=" + locale.getDisplayCountry());
            System.out.println("	docType=" + docType);
        }
        return docType;
    }

    /**
     * 获取扩展类型
     *
     * @param obj
     * @return   扩展的类型
     * @throws IOException
     * @throws WTException
     */
    public static String getECNType(WTChangeOrder2 obj) throws IOException, WTException
    {
        String objType = "";
        Locale locale = SessionHelper.manager.getLocale();
        objType = ClientTypedUtility.getLocalizedTypeName(obj, locale.CHINA);
        return objType;
    }

    /**
     * 获取properties中的值
     *
     * @param propertityFile
     *            properties的文件名
     * @param keyInProperties
     *            properties的key值
     * @return String properties的值
     **/
    public static String getPropertiesValue(String propertityFile, String keyInProperties) throws WTException
    {
        String valueInProperties = "";

        PropertyResourceBundle prBundle = (PropertyResourceBundle) PropertyResourceBundle.getBundle(propertityFile);
        try
        {
            byte[] temp = null;
            temp = keyInProperties.getBytes("GB2312");
            keyInProperties = new String(temp, "ISO-8859-1");
            temp = prBundle.getString(keyInProperties).getBytes("ISO-8859-1");
            valueInProperties = new String(temp, "GB2312");
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        return valueInProperties.trim();

    }

    /**
     * 判断必签环节是否已选  
     * 注：10.0版本已不在用此方法
     */
    public static void ifHuanjieSelected(String roleKey1, boolean activity1, String activename1, String roleKey2, boolean activity2, String activename2, String roleKey3, boolean activity3,
                                         String activename3, String roleKey4, boolean activity4, String activename4, String roleKey5, boolean activity5, String activename5, String roleKey6,
                                         boolean activity6, String activename6) throws WTException, WTPropertyVetoException
    {
        Vector v = new Vector();
        if (!ifRealValueRight(roleKey1, activity1))
            v.add(activename1);
        if (!ifRealValueRight(roleKey2, activity2))
            v.add(activename2);
        if (!ifRealValueRight(roleKey3, activity3))
            v.add(activename3);
        if (!ifRealValueRight(roleKey4, activity4))
            v.add(activename4);
        if (!ifRealValueRight(roleKey5, activity5))
            v.add(activename5);
        if (!ifRealValueRight(roleKey6, activity6))
            v.add(activename6);

        if (v != null && v.size() > 0)
        {
            Object[] param =
            { v };
            throw new WTException(new WTMessage(RESOURCE, "12", param));
        }
    }

    public static boolean ifRealValueRight(String define, boolean realvalue)
    {

    	System.out.println("define:"+define+"realvalue:"+realvalue);
        if (define != null && define.startsWith("Y") && !realvalue)
            return false;
        return true;
    }

    /**
     * 如果是非A版本, “是否受变更控制”若为“Y”，表示该小类的文档修订后，不允许再提交走文档的签审流程。
     */
    public static void NeedEC(Persistable pbo, String activityName, String sheetName) throws IOException, WTException
    {
        if (VERBOSE)
            System.out.println(">>>enter WfAugmentUtil.NeedEC --- activityName=" + activityName);

        String wfConfigFilePath = getConfigFilePath(pbo);
        if (VERBOSE)
            System.out.println("\t 签审指南路径=" + wfConfigFilePath);
        if (wfConfigFilePath == null || wfConfigFilePath.length() == 0)
            return;

        XSSFWorkbook wb = new XSSFWorkbook(new FileInputStream(wfConfigFilePath));
        if (wb == null)
            return;
        String detailType = "";
        String bigType = "";
        String docName = "";
        XSSFSheet sheet = wb.getSheet(sheetName);
        if (sheet == null)
            return;
        Iterator rows = sheet.rowIterator();
        int rowNumber = 1;
        int nActivityCol = 0;
        String cellValue = "";
        XSSFRow row;
        XSSFCell cell;
        if (pbo instanceof WTDocument)
        {
            WTDocument doc = (WTDocument) pbo;
            String docVersion = VersionControlHelper.getVersionIdentifier(doc).getValue();
            if (docVersion.equals("A"))
                return;
            docName = doc.getName();
            bigType = getDocType(doc);
            Hashtable ibaValues= IBAUtil.getIBAValues(doc);
            String docType = getPropertiesValue("ext.generic.wfaugment.wfaugment", "wf.doc.smallType");
            detailType = (String)ibaValues.get(docType);
            if (VERBOSE)
                System.out.println("\t 文档大类为 " + bigType + "，文档小类软属性为 " + docType + "，其值为 " + detailType);

            String langMark;
            int columnMark;
            if (detailType == null || detailType.length() == 0)
            {
                langMark = bigType;
                columnMark = 0;
            }
            else
            {
                langMark = detailType;
                columnMark = 1;
            }
            row = (XSSFRow) rows.next();
            do
            {
                if (!rows.hasNext())
                {
                    break;
                }
                cell = row.getCell((short) columnMark);
                if (cell != null)
                {
                    cellValue = cell.getStringCellValue().trim();
                    if (cellValue.equals(langMark))
                    {
                        rowNumber = row.getRowNum();
                        break;
                    }
                }
                row = (XSSFRow) rows.next();
            }
            while (true);
        }
        else
        {
            rowNumber = 2;
        }
        if (VERBOSE)
            System.out.println("\t rowNumber = " + rowNumber);

        row = sheet.getRow(0);
        for (int i = 0; i < row.getLastCellNum(); i++)
        {
            cell = row.getCell((short) i);
            if (cell == null)
            {
                continue;
            }
            cellValue = cell.getStringCellValue().trim();
            if (!cellValue.equals(activityName))
            {
                continue;
            }
            nActivityCol = i;
            break;
        }

        if (VERBOSE)
        {
            System.out.println("\t nActivityCol = " + nActivityCol);
        }
        XSSFRow row1 = sheet.getRow(rowNumber);
        cell = row1.getCell((short) nActivityCol);
        if (VERBOSE)
        {
            System.out.println("\t cell = " + cell);
        }
        if (cell != null)
        {
            String roleValue = cell.getStringCellValue();
            roleValue = roleValue.trim();
            if (VERBOSE)
                System.out.println("\t roleValue=" + roleValue);
            if (roleValue.startsWith("Y"))
                throw new WTException(new WTMessage(RESOURCE, "13", null));
        }
    }
   /**
    * 获取excel中指定行、列的cell值
    * @param sheet  excle中的sheet页
    * @param nRow   行值
    * @param nCol   列值
    * @return       返回excel中指定行、列的cell值
    */
    public static String getExcelCellContent(XSSFSheet sheet, int nRow, int nCol)
    {
        if (sheet == null || nRow < 0 || nCol < 0)
            return "";
        try
        {
            XSSFRow row = sheet.getRow(nRow);
            if (row == null)
                return "";
            XSSFCell aCell = row.getCell(nCol);
            if (aCell == null)
                return "";
            String content = aCell.getStringCellValue();
            if (content != null)
                content = content.trim();
            if (content == null)
                content = "";
            return content;
        }
        catch (Exception e)
        {
            System.out.println("	getExcelCellContent : error, nRow = '" + nRow + "' , nCol = '" + nCol + "'");
            e.printStackTrace();
        }
        return "";
    }

    /* 设定只读
     * 10.0版本中已不在用此方法
     * 
     */
    public static void setOnlyVaraints(ObjectReference self, String onlyStr) throws WTException
    {
        System.out.println("@@@@DEBUG by gaoxu: enter my activity....");
        System.out.println("@@@@@ onlyStr=" + onlyStr);
        wt.workflow.engine.WfActivity wfactivity = (wt.workflow.engine.WfActivity) (self.getObject());
        wt.workflow.engine.ProcessData processdata = wfactivity.getContext();
        //wt.workflow.engine.WfProcess wfprocess = wfactivity.getParentProcess();

        wt.workflow.engine.WfVariable awfvariable[] = processdata.getVariableList();
        int k = awfvariable.length;
        for (int i = 0; i < k; i++)
        {
            wt.workflow.engine.WfVariable wfvariableinfo = awfvariable[i];
            //wt.workflow.definer.WfVariableInfo wfvariableinfo=awfvariable[i];
            String varName = wfvariableinfo.getName();
            System.out.println("@@@@DEBUG by GaoXu: varName=" + varName);
            if (onlyStr.indexOf(varName) >= 0)
            {
                System.out.println("@@@@@ set Read Only............");
                System.out.println(wfvariableinfo.isReadOnly());
                //System.out.println(wfvariableinfo.getValue().toString());
                wfvariableinfo.setReadOnly(true);

                awfvariable[i] = wfvariableinfo;
                processdata.setVariables(awfvariable);
                wfactivity.setContext(processdata);
                wt.fc.PersistenceHelper.manager.save(wfactivity);
                wt.fc.PersistenceHelper.manager.refresh(wfactivity);
                System.out.println(wfvariableinfo.isReadOnly());
            }
        }
    } 
    
    /**
     * 设置页面中checkbox只读
     *
     * @param httpservletrequest
     *            页面的request对象
     * @param propertyModel
     *            jsp页面中旧的propertyModel值
     * @param str
     *    		  jsp页面中传来的一段字符串         
     * @return ComponentModel 返回新的propertyModel值
     **/
    public static ComponentModel setReadOnlyJspComponent (HttpServletRequest  httpservletrequest, ComponentModel propertyModel, String str) throws WTException{
    	System.out.println(">>>>" + CLASSNAME + ".setReadOnlyJspComponent()");
    	ComponentModel returnPropertyModel=propertyModel;
    	Object obj = httpservletrequest.getParameter("oid");
        NmOid projOid = new NmOid(obj.toString());
        WorkItem workitem=(WorkItem)projOid.getRef();
        WfActivity wfactivity=(WfActivity)workitem.getSource().getObject();
        ProcessData processdata=wfactivity.getContext();
        String onlyString=(String) processdata.getValue("OnlyString");
        if(VERBOSE) 
    		System.out.println("OnlyString<<<<" + onlyString);
      //解析工作流模板中"OnlyString",将其中变量设为只读
        if(!onlyString.equals("")){
            Object object=RenderPropertyLabelTag.getPropertyValue(returnPropertyModel, str);
            GUIComponentArray gca=(GUIComponentArray)object; 
       	    for(int i=0;i<gca.size();i++){
       	 	  if(gca.get(i) instanceof CheckBox){
       	 		  CheckBox checkBox= (CheckBox)gca.get(i);
       	 		  String checkBoxName=checkBox.getName().replaceAll("CustActVar","");
       	 		  if(VERBOSE)
       	    		System.out.println("checkBoxName<<<<" + checkBoxName);
       	 		  if(onlyString.contains(checkBoxName)){
    	            ((CheckBox)gca.get(i)).setReadOnly(true);
    	          //  ((CheckBox)gca.get(i)).setHiddenId(true);
       	 		    ((CheckBox)gca.get(i)).setEnabled(false);
       	 		  }
       	 	  }
       	    }
        }
    	if(VERBOSE)
    		System.out.println("<<<<" + CLASSNAME + ".setReadOnlyJspComponent()");
		return returnPropertyModel; 
    	
    }

}


